package com.demo.action;

import com.demo.entity.Person;
import com.demo.service.PersonService;
import com.opensymphony.xwork2.ActionSupport;

import java.util.List;

public class PersonAction extends ActionSupport{
	
	private Person person;
	private PersonService personService;
	private List<Person> list;
	
	//定义savePerson()方法，调用PersonService中的savePerson()方法
	public String savePerson(){
		personService.savePerson(person);
		return "savesuccess";
	}
	//定义deletePerson()方法，调用PersonService中的deletePerson()方法
	public String deletePerson(){
		personService.deletePerson(person);
		return "deletesuccess";
	}
	//定义updatePerson()方法，调用PersonService中的updatePerson()方法
	public String updatePerson(){
		personService.updatePerson(person);
		return "updatesuccess";
	}
	//定义queryPerson()方法，调用PersonService中的queryPerson()方法
	public String queryPerson() {
		list = personService.queryPerson();
		return SUCCESS;
	}
	//定义findPersonById()方法，调用PersonService中的findPersonById()方法
	public String findPersonById(){
		person=personService.findPersonById(person.getId());
		if(person==null){              //判断返回结果是否为空
			return "noresult";
		}
		else
			return "findresult";
	}
	//生成get跟set方法
	public Person getPerson() {
		return person;
	}
	public void setPerson(Person person) {
		this.person = person;
	}
	public PersonService getPersonService() {
		return personService;
	}
	public void setPersonService(PersonService personService) {
		this.personService = personService;
	}
	public List<Person> getList() {
		return list;
	}
	public void setList(List<Person> list) {
		this.list = list;
	}
	
}
